var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJlNjkzMmI1Ny1iMWNmLTQyMmUtYjljMi03YjdmZDI4ZjM0ZGEiLCJzdWIiOiJBY2Nlc3MgVG9rZW4iLCJleHAiOjE3MDIwNDQyMTAsImlzcyI6IktvYWxhIERyaXZlciIsImlhdCI6MTcwMjA0MDYxMCwidXNlcklkIjoiMSIsInJvbGUiOiJ1c2VyIn0.rEi2xyRMy74E9fCqifM0CgnHTAwGHXaUeos8JTFvIto'
const apiUrl = process.env.REACT_APP_API_URL;

function downloadFiles(fileIds, fileName) {
    if (localStorage.getItem('token') !== null) {
        token = localStorage.getItem('token')
    }
    fetch(apiUrl + `/file/getDownLoadToken?fileIds=${fileIds.join(',')}`,
    {
        method: 'GET',
        headers: {
          'Authorization': `Bearer ${token}`,
          'Referrer-Policy': 'no-referrer',
        }
    }).then(response => {
        return response.json();
    }).then(res => {
        window.location.href = apiUrl + '/file/downloadByToken?token=' + res.data.token;
    }).catch(error => console.error('下载文件时发生错误:', error));

}

export default downloadFiles;